<template>
	<div></div>
</template>
<script>
	import util from "../../util/textUtil.js"
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: "支付"
			});
			this.isWeixinOrAlipay();
		},
		methods: {
			getInfo: function(code, tradeId) {
				let that = this;
				uni.request({
					url: getApp().globalData.baseUrl + 'app/wxLogin/' + code,
					method: 'GET',
					success(res) {
						console.log(res);
						if (res.data.code == 0) {
							getApp().globalData.token = res.data.token;
							uni.navigateTo({
								url: "wx?tradeId=" + tradeId + "&price=" + this.price
							});
						}
					}
				});
			},
			isWeixinOrAlipay: function() {
				let tradeId = util.getUrlKey("tradeId");
				var ua = window.navigator.userAgent.toLowerCase();
				//判断是不是微信
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					let code = util.getUrlParam("code");
					if (getApp().globalData.token == null) {
						this.getInfo(code, tradeId)
					} else {
						uni.navigateTo({
							url: "wx?tradeId=" + tradeId + "&price=" + this.price
						});
					}
				}
				//判断是不是支付宝
				else if (ua.match(/AlipayClient/i) == 'alipayclient') {
					let code = util.getUrlKey("auth_code"); //是否存在code
					uni.navigateTo({
						url: "ailpay?tradeId=" + tradeId + "&price=" + this.price+"&code="+code
					});
				} else {
					uni.showToast({
						title: "未知平台！",
						icon: 'none'
					});
				}

			}
		}
	}
</script>

<style>
</style>
